package com.gree.scmservice.dao;

import com.gree.common.entity.SysDictData;
import com.gree.common.entity.SysDictType;
import com.gree.common.entity.TablePageData;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.pager.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 180686 on 2021/3/24 13:43
 */

@Repository
public class SysDictTypeDao {

    @Autowired
    private Dao dao;

    public List<SysDictType> querySysDictType(Cnd cnd, Pager pager) {
        List<SysDictType> sysDictTypeList = dao.query(SysDictType.class,cnd,pager);
        return sysDictTypeList;
    }

    public TablePageData<SysDictType> selectSysDictTypeList(SysDictType sysDictType){
        Pager pager = dao.createPager(sysDictType.getPageNum(), sysDictType.getPageSize());
        sysDictType.setBaseEntityNull();
        Cnd cnd = Cnd.from(dao, sysDictType);
        List query = dao.query(SysDictType.class, cnd, pager);
        pager.setRecordCount(dao.count(SysDictType.class, cnd));
        TablePageData tablePageData = new TablePageData(query, pager);
        return tablePageData;
    }

    public List<SysDictType> querySysDictTypeAll() {
        List<SysDictType> sysDictTypeList = dao.query(SysDictType.class,null);
        return sysDictTypeList;
    }

    public SysDictType fetchSysDictTypeByDictId(Long dictId) {
        SysDictType sysDictType = dao.fetch(SysDictType.class,dictId);
        return sysDictType;
    }

    public SysDictType fetchSysDictTypeByDictType(String dictType) {
        SysDictType sysDictType = dao.fetch(SysDictType.class,Cnd.where("dict_type","=",dictType));
        return sysDictType;
    }

    public SysDictType fetchSysDictTypeByDictName(String dictName) {
        SysDictType sysDictType = dao.fetch(SysDictType.class,Cnd.where("dict_name","=",dictName));
        return sysDictType;
    }

    public int deleteSysDictTypeByDictIds(Long[] dictIds) {
        int result = dao.clear(SysDictType.class,Cnd.where("dict_id","in",dictIds));
        return result;
    }

    public SysDictType insertSysDictType(SysDictType sysDictType) {
        SysDictType result = dao.insert(sysDictType);
        return result;
    }

    public int updateSysDictType(SysDictType sysDictType) {
        int result = dao.update(sysDictType);
        return result;
    }

}
